<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<%@page import="java.util.*, java.sql.*" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Where You From?</title>
</head>
<body>

<% 
	String degreeMajorParam = request.getParameter("degreeMajor");
	String degreeDateParam = request.getParameter("degreeDate");
	String degreeGPAParam = request.getParameter("degreeGPA");
	String degreeTypeParam = request.getParameter("degreeType");
	String degreeFileParam = request.getParameter("degreeFile");
	String otherMajorParam = request.getParameter("otherMajor");
	String degreeMajorIDParam = "";
	
	if( degreeFileParam == null)
	{
		degreeFileParam = "No resume/transcript received";
		
	}
	 
	String[] tokens = new String[10];
	tokens = degreeMajorParam.split("#");
    if(tokens.length > 1){
    	
        degreeMajorParam = tokens[0];
        degreeMajorIDParam = "" + tokens[1].charAt(tokens[1].length() - 1);
    }
	
	Vector degreeInfo = (Vector) session.getAttribute( "degreeInfoSes" );
	
	if( degreeInfo == null ) {
		degreeInfo = new Vector();
	}
	
	if(degreeMajorParam.equals("other"))
	{
		Class.forName("org.postgresql.Driver");

		Connection connect = DriverManager.getConnection("jdbc:postgresql://localhost/tester?user=postgres&password=admin");
		Statement stmt = connect.createStatement();
		Statement stmt2 = connect.createStatement();
		ResultSet rset;
		ResultSet rset2;
	
		rset = stmt.executeQuery("SELECT * FROM disciplines WHERE name='" + otherMajorParam + "'");
		if ( !rset.next() )
		{
			stmt.execute("INSERT INTO disciplines (name) VALUES ('" + otherMajorParam + "')");
			rset2 = stmt2.executeQuery("SELECT last_value FROM disciplines_id_seq");
			while(rset2.next())
			{
				degreeMajorIDParam = rset2.getString("last_value");
			}
		}
	
		
		
		degreeMajorParam = otherMajorParam;
	}
	
	degreeInfo.add(session.getAttribute("degreeUniversityIDSes"));
	degreeInfo.add(degreeMajorIDParam);
	degreeInfo.add(degreeDateParam);
	degreeInfo.add(degreeGPAParam);
	degreeInfo.add(degreeTypeParam);
	degreeInfo.add(degreeFileParam);
	degreeInfo.add(session.getAttribute("degreeUniversitySes"));
	degreeInfo.add(degreeMajorParam);
	

	session.setAttribute( "degreeInfoSes", degreeInfo);



%>
	
	
	<%= session.getAttribute("firstNameSes") %>
	<%= session.getAttribute("middleInitialSes") %>
	<%= session.getAttribute("lastNameSes") %><br>
	Citizen of <%= session.getAttribute("citizenSes") %><br>
	Resident of <%= session.getAttribute("residentSes") %><br>
	Address: <%= session.getAttribute("streetSes") %><br>
	City: <%= session.getAttribute("citySes") %><br>
	<%
	if( session.getAttribute("stateSes") != null )
	{ %>
		State: <%= session.getAttribute("stateSes") %><br>
	<%
	}
	else
	{ %>
		Country Code: <%= session.getAttribute("countryCodeSes") %><br>
		
	<% } %>
	Zip: <%= session.getAttribute("zipSes") %><br>
	Phone Number: (<%= session.getAttribute("areaCodeSes") %>) <%= session.getAttribute("phoneSes") %><br>
	<br>
	
	<%
	if ( session.getAttribute("permanentResident") != null)
	{ %>
		Domestic Status: <%= session.getAttribute("permanentResident") %><br><br>
	<% } 
	
	for( int i = 0; i< degreeInfo.size(); i=i+8 )
	{ %>
		University: <%= ((Vector)session.getAttribute("degreeInfoSes")).elementAt(i+6) %><br>
		Major: <%= ((Vector)session.getAttribute("degreeInfoSes")).elementAt(i+7) %><br>
		Date degree Received: <%= ((Vector)session.getAttribute("degreeInfoSes")).elementAt(i+2) %><br>
		GPA: <%= ((Vector)session.getAttribute("degreeInfoSes")).elementAt(i+3) %><br>
		Degree Type: <%= ((Vector)session.getAttribute("degreeInfoSes")).elementAt(i+4) %><br>
		Resume: <%= ((Vector)session.getAttribute("degreeInfoSes")).elementAt(i+5) %><br><br>
		
	<% } %>

	

	If you obtained any other degrees, please say so now<br>
	
	<form method="GET" action="6_DegreeLocation.jsp">
	<input type="submit" value="Submit More Degrees"/>
	</form><br><br>
	
	<form method="GET" action="10_Specialization.jsp">
	<input type="submit" value="Done"/>
	</form>
	
	

	
	
	

<br><br>


</body>
</html>